﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AVIS.TaskScheduler.ServerNode
{
    public class HangfireSettings
    {
        public string ServerName
        {
            get
            {
                return ConfigurationManager.AppSettings["Hangfire.ServerName"] ?? "Avis";
            }
        }

        public int WorkerCount
        {
            get
            {
                int workerCount = 0;
                var strWorkerCount = ConfigurationManager.AppSettings["Hangfire.WorkerCount"];
                if (!string.IsNullOrWhiteSpace(strWorkerCount) && int.TryParse(strWorkerCount, out workerCount))
                {
                    return workerCount;
                }

                return Math.Min(Environment.ProcessorCount * 5, 20);
            }
        }

        public string[] Queues
        {
            get
            {
                var strQueues = ConfigurationManager.AppSettings["Hangfire.Queues"];
                if (string.IsNullOrWhiteSpace(strQueues))
                {
                    strQueues = "default";
                }

                return strQueues.ToLower().Split(',');
            }
        }
    }
}
